package Thread;

import javax.imageio.plugins.tiff.TIFFImageReadParam;
import java.util.Timer;

/**
 * @description: RunnableText
 * 共享资源  多个代理
 * 会出现 并发问题 （需要保持线程安全）
 * Thread.currentThread() 当前线程
 * Thread.sleep()   暂停线程
 * Thread.yield()   礼让线程 (类似暂停，有几率失败) 将线程变为 就绪状态 而不是 阻塞状态
 * xx.join()        合并线程
 * @date: 2019/12/19 18:14
 * @author: Vicuna
 */


public class RunnableText implements Runnable {
    private int tickets = 100;

    @Override
    public void run() {
        while (true) {
            if (tickets < 0)
                break;
            try {
                Thread.sleep(300);
                // Thread.yield();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "----->" + tickets--);
        }
    }

    public static void main(String[] args) {
        RunnableText man = new RunnableText();

        // 匿名函数 共享资源
        new Thread(man, "one").start();
        new Thread(man, "two").start();
        new Thread(man, "two").start();



    }
}
